#include <my_head.h>

int main(int argc, const char *argv[]){
    FILE *fp = NULL;
    if(NULL == (fp = fopen("/etc/passwd", "r")))
        ERR_LOG("fopen error");
    char input_name[32];
    printf("输入用户名");
    scanf("%s", input_name);
    char buff[4096] = {0};
    char usr_name[32] = {0};
    char usr_id[32] = {0};
    int int_usr_id = 0;
    int i = 0;
    int j = 0;
    while(fgets(buff, sizeof(buff), fp)){
        i = 0;
        while(':' != buff[i]){
            usr_name[i] = buff[i];
            i++;
        }
        usr_name[i] = '\0'; 
        if(!strcmp(usr_name, input_name)){
            i++; 
            while(':' != buff[i]){
                i++;
            }
            i++; 
            while(':' != buff[i]){
                usr_id[j++] = buff[i++];
            }
            usr_id[j] = '\0';
            int_usr_id = atoi(usr_id);
            printf("%d\n", int_usr_id);
            fclose(fp);
            return 0;
        }
    }
    printf("用户信息输入错误未找到\n");
    fclose(fp);
    return 0;
}